package com.zhw.goshopping.controller;

import com.zhw.goshopping.common.pojo.EasyUIDataGridResult;
import com.zhw.goshopping.common.pojo.GoShoppingResult;
import com.zhw.goshopping.pojo.TbItem;
import com.zhw.goshopping.service.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Create by zhaihongwei on 2018/3/17
 *
 * 商品管理Controller
 */
@Controller
public class ItemController {

    @Autowired
    private ItemService itemService;

    /**
     * 根据商品id查询商品信息
     * @param itemId
     * @return
     */
    @RequestMapping("/item/{itemId}")
    @ResponseBody
    public TbItem getItemById(@PathVariable long itemId) {

        return itemService.getItemById(itemId);
    }

    /**
     * 分页查询商品信息
     * @param page
     * @param rows
     * @return
     */
    @RequestMapping("/item/list")
    @ResponseBody
    public EasyUIDataGridResult getItemList(Integer page,Integer rows) {
        EasyUIDataGridResult itemList = itemService.getItemList(page,rows);
        return itemList;
    }

    /**
     * 添加商品信息
     * @param item
     * @param desc
     * @return
     */
    @RequestMapping(value = "/item/save",method = RequestMethod.POST)
    @ResponseBody
    public GoShoppingResult addItem(TbItem item,String desc) {
        GoShoppingResult result = itemService.addItem(item,desc);
        return result;
    }

}
